function  check_username() {
    $("#username").blur(function () {
        var username=$(this).val()
        // var d={'type':'check_username','data':username}
        // debugger
        $.post(url = '/index/',
            data={'type':'check_username','username':username},
            function (d,status,xhr) {

                if ( d.code != 0 ){
                  var err=d.errmsg
                    $('#username_err').text(err).css('display','block')
                }
                else
                    {
                    $('#username_err').text('').css('display','none')
                }
                // debugger
            },
            dataType='json')
    });
}


function commit_form(types) {
    if (  $('#username_err').css('display') == 'none' ) {   //判断表单 验证  以及 用户名是否占用

        if ($('#signupForm').valid() ){
// {#                    var name = $("#signupForm").serializeArray() // form 表单 内容序列化#}
// {#                    var data = JSON.stringify(name)   //  转换为json格式字符串 [{key,val},{key,val}....#}

        var arr = {};   //自定义 提取 表单数据
        var select = $("#myModal input[name = topic]")
        $("#myModal input[name != topic]").each(function () {   //选择 表单中 不包括topic  爱好的input
            arr[$(this).attr('name')] = $(this).val();  //{key:val,key,val.....}
        });

        $("#myModal input[name = topic]").each(function () {   //选择 表单中 包括topic  爱好的input
            var s = $(this)
            if ($(this).prop('checked')) {

                arr[$(this).attr('id')] = $(this).val();  //{key:val,key,val.....}
            }

        });
            if (uid) {
                $.axspost(url = '/index/', {'type': types, 'data': JSON.stringify(arr),'uid':uid});
            }
            else {
                $.axspost(url = '/index/', {'type': types, 'data': JSON.stringify(arr)});
            }
        // {#        debugger#}
        // {#        }#}
        // {#        else{#}
        // {##}
        // {#            console.log(123)#}
        // {#            return false#}
        // {#        }#}

    }

    }
    else {
        return false
    }



    }


$(document).ready(function(){
    // $("tr:even").css("background-color","#CCEEFF")
    $("tr:first").css("background-color","#DDFF77")




      $("#signupForm").validate({
          errorPlacement : function(error, element) {     //message 错误提示的显示位置
        if (element.is(":radio"))
            error.appendTo(element.parent().next());
        else if (element.is(":checkbox"))
            error.appendTo(element.parent().parent());
        else
            error.appendTo(element.parent());
    },

	    rules: {
	      firstname: "required",
	      username: {
	        required: true,
	        minlength: 2
	      },
	      password: {
	        required: true,
	        minlength: 5
	      },
	      confirm_password: {
	        required: true,
	        minlength: 5,
	        equalTo: "#password"
	      },
	      email: {
	        required: true,
	        email: true
	      },
	      "topic[]": {
	        // required: "#newsletter:checked",
	        minlength: 2
	      },
            newsletter: {
	            required: true,
	             // minlength: 2
	      },
	      agree: "required"
	    },
	    messages: {
	      firstname: "请输入您的名字",
	      // lastname: "请输入您的姓氏",
	      username: {
	        required: "请输入用户名",
	        minlength: "用户名必需由两个字母组成"
	      },
	      password: {
	        required: "请输入密码",
	        minlength: "密码长度不能小于 5 个字母"
	      },
	      confirm_password: {
	        required: "请输入密码",
	        minlength: "密码长度不能小于 5 个字母",
	        equalTo: "两次密码输入不一致"
	      },
	      email: "请输入一个正确的邮箱",
	      agree: "请接受我们的声明",
           newsletter:"请选择爱好",
	      "topic": "请选择两个主题",
	    }
	});






});


